package org.stream.answerduel.vo;

import org.springframework.beans.BeanUtils;
import org.stream.answerduel.entity.User;
import org.stream.answerduel.vo.UserVo;

import lombok.Data;

@Data
public class MatchingUser extends UserVo
{
    private int priority = 0; //优先级

    private long waitTime = 0; //匹配等待的时间，单位是毫秒

    private int diff = 200; //匹配允许的分数差，每隔2秒增加

    private long lastAddTime = 0; //上次diff增加的时间

    private long lastTime = System.currentTimeMillis();

    public MatchingUser(){

    }

    public MatchingUser(User user)
    {
        BeanUtils.copyProperties(user, this);
    }

    public MatchingUser(UserVo user)
    {
        BeanUtils.copyProperties(user, this);
    }

    public MatchingUser(UserVo user,int priority){
        BeanUtils.copyProperties(user, this);
        this.priority=priority;
    }
    public void update()
    {
        if(priority!=-1)
        {
            priority++;
        }
        waitTime += System.currentTimeMillis() - lastTime;
        lastTime = System.currentTimeMillis();
        if(waitTime - lastAddTime >= 2000)
         {   
            lastAddTime = waitTime;
             diff *= 2;
         }
    }
}